import Bus from "./bus.js";
const baseUrl = "http://localhost:8080";

let vm = new Vue({
    el: "#vue-login",
    data() {
        return {
            user: {},
            // 用来保存user对象信息，并传递给admin/index.html页面
            user_info: {}
        }
    },
    methods: {
        // 登录
        doLogin() {
            // alert(this.user);
            axios({
                method: "post",
                url: baseUrl + "/hotel/manage/doLogin",
                responseType: "json",
                data: this.user
            }).then(response => {
                // console.log("debug => ",response);
                swal({
                    title: response.data.login_info.message,
                    text: "点击确定继续",
                    icon: response.data.login_info.state,
                    button: "确定",
                }).then(value => {                   
                    // console.log(response)
                    if(response.data.login_info.state === "error") {
                        // console.log("123",response.data.login_info);
                        this.toHref(response.data.login_info.url);
                        return false;
                    }
                    this.user_info = response.data.login_info.user;
                    console.log("user_info",this.user_info);
                    console.log(Bus);
                    Bus.bus.$emit("user_info",this.user_info);
                    //this.$emit("user_info", user_info);   
                    this.toHref(response.data.login_info.url + "?user_id=" + response.data.login_info.user.id);
                    return false;
                })
            })
        },
        // 登录后的路径跳转
        toHref(url) {
            // console.log("执行到这里了")
            window.location.href = baseUrl + "/" + url;
        }
    },
})